package review;

/**
 * Description:
 *
 * @Author:
 * @Date: 2024/7/20 15:38
 */
public class MyInterrupt3 {
    public static void main(String[] args) throws InterruptedException {
        /*// 1. 打断阻塞的线程
        Thread t1 = new Thread(() -> {
            System.out.println("t1...正在运行");
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "t1");
        t1.start();
        Thread.sleep(500L);
        t1.interrupt();
        System.out.println(t1.isInterrupted());*/

        // 2.打断正常的线程
        Thread t2 = new Thread(() -> {
            while(true) {
                Thread current = Thread.currentThread();
                boolean interrupted = current.isInterrupted();
                if (interrupted) {
                    System.out.println("打断状态："+interrupted);
                    break;
                }
            }
        }, "t2");
        t2.start();
        Thread.sleep(500L);
        t2.interrupt();
        System.out.println(t2.isInterrupted());
    }

}
